package com.ray.base.utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 数据库
 */
public class DBHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "data.db";  //数据库名字
    private static final int DATABASE_VERSION = 1;         //数据库版本号

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    /**
     * 创建数据库表：person
     * _id为主键，自增
     **/
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        Log.i("DBHelper:", "创建据库表！");
        //其中id唯一约束不能重复
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS record (num integer primary key autoincrement, " +
                "title varchar(40), category varchar(10),duration long(10), detail varchar(100), url varchar(100),id varchar(20) unique,description varchar(100))");
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS favorite (num integer primary key autoincrement, " +
                "title varchar(40), category varchar(10),duration long(10), detail varchar(100), url varchar(100),id varchar(20) unique,description varchar(100))");
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS download (num integer primary key autoincrement," +
                "title varchar(40), category varchar(10),duration long(10), detail varchar(100), url varchar(100),id varchar(20) unique,description varchar(100))");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
    }

    @Override
    public void onOpen(SQLiteDatabase sqLiteDatabase) {
        super.onOpen(sqLiteDatabase);
    }
}
